// $ANTLR 3.1.2 C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g 2009-03-26 21:11:27

 package real;
  
 import real.lang.*;
 import real.evaluation.*;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;


import org.antlr.runtime.tree.*;

public class RealSetQueryParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "QUESTION", "SEMICOLON", "LCURLY", "RCURLY", "NEWLINE", "ID", "ASSIGN", "INT", "STRING", "WS", "CMT"
    };
    public static final int CMT=14;
    public static final int WS=13;
    public static final int NEWLINE=8;
    public static final int QUESTION=4;
    public static final int RCURLY=7;
    public static final int ASSIGN=10;
    public static final int LCURLY=6;
    public static final int INT=11;
    public static final int SEMICOLON=5;
    public static final int ID=9;
    public static final int EOF=-1;
    public static final int STRING=12;

    // delegates
    // delegators


        public RealSetQueryParser(TokenStream input) {
            this(input, new RecognizerSharedState());
        }
        public RealSetQueryParser(TokenStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        
    protected TreeAdaptor adaptor = new CommonTreeAdaptor();

    public void setTreeAdaptor(TreeAdaptor adaptor) {
        this.adaptor = adaptor;
    }
    public TreeAdaptor getTreeAdaptor() {
        return adaptor;
    }

    public String[] getTokenNames() { return RealSetQueryParser.tokenNames; }
    public String getGrammarFileName() { return "C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g"; }


    public static class query_return extends ParserRuleReturnScope {
        public RealQuery result;
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "query"
    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:39:1: query returns [RealQuery result] : ( statements )? set QUESTION EOF ;
    public final RealSetQueryParser.query_return query() throws RecognitionException {
        RealSetQueryParser.query_return retval = new RealSetQueryParser.query_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token QUESTION3=null;
        Token EOF4=null;
        RealSetQueryParser.statements_return statements1 = null;

        RealSetQueryParser.set_return set2 = null;


        CommonTree QUESTION3_tree=null;
        CommonTree EOF4_tree=null;

        try {
            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:40:3: ( ( statements )? set QUESTION EOF )
            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:41:3: ( statements )? set QUESTION EOF
            {
            root_0 = (CommonTree)adaptor.nil();

            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:41:3: ( statements )?
            int alt1=2;
            int LA1_0 = input.LA(1);

            if ( (LA1_0==ID) ) {
                int LA1_1 = input.LA(2);

                if ( (LA1_1==ASSIGN) ) {
                    alt1=1;
                }
            }
            switch (alt1) {
                case 1 :
                    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:41:3: statements
                    {
                    pushFollow(FOLLOW_statements_in_query132);
                    statements1=statements();

                    state._fsp--;

                    adaptor.addChild(root_0, statements1.getTree());

                    }
                    break;

            }

            pushFollow(FOLLOW_set_in_query135);
            set2=set();

            state._fsp--;

            adaptor.addChild(root_0, set2.getTree());
            QUESTION3=(Token)match(input,QUESTION,FOLLOW_QUESTION_in_query137); 
            QUESTION3_tree = (CommonTree)adaptor.create(QUESTION3);
            adaptor.addChild(root_0, QUESTION3_tree);

            EOF4=(Token)match(input,EOF,FOLLOW_EOF_in_query139); 
            EOF4_tree = (CommonTree)adaptor.create(EOF4);
            adaptor.addChild(root_0, EOF4_tree);


              RealQuery rq = new RealQuery();
              retval.result = rq;
              

            }

            retval.stop = input.LT(-1);

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "query"

    public static class statements_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "statements"
    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:50:1: statements : ( expression SEMICOLON | expression NEWLINE )+ ;
    public final RealSetQueryParser.statements_return statements() throws RecognitionException {
        RealSetQueryParser.statements_return retval = new RealSetQueryParser.statements_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token SEMICOLON6=null;
        Token NEWLINE8=null;
        RealSetQueryParser.expression_return expression5 = null;

        RealSetQueryParser.expression_return expression7 = null;


        CommonTree SEMICOLON6_tree=null;
        CommonTree NEWLINE8_tree=null;

        try {
            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:51:3: ( ( expression SEMICOLON | expression NEWLINE )+ )
            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:51:5: ( expression SEMICOLON | expression NEWLINE )+
            {
            root_0 = (CommonTree)adaptor.nil();

            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:51:5: ( expression SEMICOLON | expression NEWLINE )+
            int cnt2=0;
            loop2:
            do {
                int alt2=3;
                alt2 = dfa2.predict(input);
                switch (alt2) {
            	case 1 :
            	    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:51:6: expression SEMICOLON
            	    {
            	    pushFollow(FOLLOW_expression_in_statements164);
            	    expression5=expression();

            	    state._fsp--;

            	    adaptor.addChild(root_0, expression5.getTree());
            	    SEMICOLON6=(Token)match(input,SEMICOLON,FOLLOW_SEMICOLON_in_statements166); 
            	    SEMICOLON6_tree = (CommonTree)adaptor.create(SEMICOLON6);
            	    adaptor.addChild(root_0, SEMICOLON6_tree);


            	    }
            	    break;
            	case 2 :
            	    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:51:28: expression NEWLINE
            	    {
            	    pushFollow(FOLLOW_expression_in_statements169);
            	    expression7=expression();

            	    state._fsp--;

            	    adaptor.addChild(root_0, expression7.getTree());
            	    NEWLINE8=(Token)match(input,NEWLINE,FOLLOW_NEWLINE_in_statements171); 
            	    NEWLINE8_tree = (CommonTree)adaptor.create(NEWLINE8);
            	    adaptor.addChild(root_0, NEWLINE8_tree);


            	    }
            	    break;

            	default :
            	    if ( cnt2 >= 1 ) break loop2;
                        EarlyExitException eee =
                            new EarlyExitException(2, input);
                        throw eee;
                }
                cnt2++;
            } while (true);


            }

            retval.stop = input.LT(-1);

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "statements"

    public static class expression_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "expression"
    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:53:1: expression : assignment ;
    public final RealSetQueryParser.expression_return expression() throws RecognitionException {
        RealSetQueryParser.expression_return retval = new RealSetQueryParser.expression_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        RealSetQueryParser.assignment_return assignment9 = null;



        try {
            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:53:13: ( assignment )
            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:53:15: assignment
            {
            root_0 = (CommonTree)adaptor.nil();

            pushFollow(FOLLOW_assignment_in_expression183);
            assignment9=assignment();

            state._fsp--;

            adaptor.addChild(root_0, assignment9.getTree());

            }

            retval.stop = input.LT(-1);

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "expression"

    public static class assignment_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "assignment"
    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:55:1: assignment : ID ASSIGN value ;
    public final RealSetQueryParser.assignment_return assignment() throws RecognitionException {
        RealSetQueryParser.assignment_return retval = new RealSetQueryParser.assignment_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token ID10=null;
        Token ASSIGN11=null;
        RealSetQueryParser.value_return value12 = null;


        CommonTree ID10_tree=null;
        CommonTree ASSIGN11_tree=null;

        try {
            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:55:13: ( ID ASSIGN value )
            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:55:15: ID ASSIGN value
            {
            root_0 = (CommonTree)adaptor.nil();

            ID10=(Token)match(input,ID,FOLLOW_ID_in_assignment192); 
            ID10_tree = (CommonTree)adaptor.create(ID10);
            adaptor.addChild(root_0, ID10_tree);

            ASSIGN11=(Token)match(input,ASSIGN,FOLLOW_ASSIGN_in_assignment194); 
            ASSIGN11_tree = (CommonTree)adaptor.create(ASSIGN11);
            adaptor.addChild(root_0, ASSIGN11_tree);

            pushFollow(FOLLOW_value_in_assignment196);
            value12=value();

            state._fsp--;

            adaptor.addChild(root_0, value12.getTree());

            }

            retval.stop = input.LT(-1);

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "assignment"

    public static class value_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "value"
    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:57:1: value : ( constant | set );
    public final RealSetQueryParser.value_return value() throws RecognitionException {
        RealSetQueryParser.value_return retval = new RealSetQueryParser.value_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        RealSetQueryParser.constant_return constant13 = null;

        RealSetQueryParser.set_return set14 = null;



        try {
            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:57:7: ( constant | set )
            int alt3=2;
            int LA3_0 = input.LA(1);

            if ( ((LA3_0>=INT && LA3_0<=STRING)) ) {
                alt3=1;
            }
            else if ( (LA3_0==LCURLY||LA3_0==ID) ) {
                alt3=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 3, 0, input);

                throw nvae;
            }
            switch (alt3) {
                case 1 :
                    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:57:9: constant
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    pushFollow(FOLLOW_constant_in_value204);
                    constant13=constant();

                    state._fsp--;

                    adaptor.addChild(root_0, constant13.getTree());

                    }
                    break;
                case 2 :
                    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:57:20: set
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    pushFollow(FOLLOW_set_in_value208);
                    set14=set();

                    state._fsp--;

                    adaptor.addChild(root_0, set14.getTree());

                    }
                    break;

            }
            retval.stop = input.LT(-1);

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "value"

    public static class constant_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "constant"
    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:59:1: constant : ( INT | STRING );
    public final RealSetQueryParser.constant_return constant() throws RecognitionException {
        RealSetQueryParser.constant_return retval = new RealSetQueryParser.constant_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token set15=null;

        CommonTree set15_tree=null;

        try {
            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:59:11: ( INT | STRING )
            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:
            {
            root_0 = (CommonTree)adaptor.nil();

            set15=(Token)input.LT(1);
            if ( (input.LA(1)>=INT && input.LA(1)<=STRING) ) {
                input.consume();
                adaptor.addChild(root_0, (CommonTree)adaptor.create(set15));
                state.errorRecovery=false;
            }
            else {
                MismatchedSetException mse = new MismatchedSetException(null,input);
                throw mse;
            }


            }

            retval.stop = input.LT(-1);

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "constant"

    public static class set_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "set"
    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:61:1: set : ( ID | set_constr );
    public final RealSetQueryParser.set_return set() throws RecognitionException {
        RealSetQueryParser.set_return retval = new RealSetQueryParser.set_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token ID16=null;
        RealSetQueryParser.set_constr_return set_constr17 = null;


        CommonTree ID16_tree=null;

        try {
            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:61:5: ( ID | set_constr )
            int alt4=2;
            int LA4_0 = input.LA(1);

            if ( (LA4_0==ID) ) {
                alt4=1;
            }
            else if ( (LA4_0==LCURLY) ) {
                alt4=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 4, 0, input);

                throw nvae;
            }
            switch (alt4) {
                case 1 :
                    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:61:7: ID
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    ID16=(Token)match(input,ID,FOLLOW_ID_in_set230); 
                    ID16_tree = (CommonTree)adaptor.create(ID16);
                    adaptor.addChild(root_0, ID16_tree);


                    }
                    break;
                case 2 :
                    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:61:12: set_constr
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    pushFollow(FOLLOW_set_constr_in_set234);
                    set_constr17=set_constr();

                    state._fsp--;

                    adaptor.addChild(root_0, set_constr17.getTree());

                    }
                    break;

            }
            retval.stop = input.LT(-1);

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "set"

    public static class set_constr_return extends ParserRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "set_constr"
    // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:63:1: set_constr : LCURLY ;
    public final RealSetQueryParser.set_constr_return set_constr() throws RecognitionException {
        RealSetQueryParser.set_constr_return retval = new RealSetQueryParser.set_constr_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        Token LCURLY18=null;

        CommonTree LCURLY18_tree=null;

        try {
            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:63:13: ( LCURLY )
            // C:\\Users\\ewger\\workspace\\real\\src\\RealSetQuery.g:64:3: LCURLY
            {
            root_0 = (CommonTree)adaptor.nil();

            LCURLY18=(Token)match(input,LCURLY,FOLLOW_LCURLY_in_set_constr246); 
            LCURLY18_tree = (CommonTree)adaptor.create(LCURLY18);
            adaptor.addChild(root_0, LCURLY18_tree);


                
                

            }

            retval.stop = input.LT(-1);

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (CommonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "set_constr"

    // Delegated rules


    protected DFA2 dfa2 = new DFA2(this);
    static final String DFA2_eotS =
        "\16\uffff";
    static final String DFA2_eofS =
        "\16\uffff";
    static final String DFA2_minS =
        "\1\6\1\4\1\uffff\1\6\1\uffff\3\5\6\uffff";
    static final String DFA2_maxS =
        "\1\11\1\12\1\uffff\1\14\1\uffff\3\10\6\uffff";
    static final String DFA2_acceptS =
        "\2\uffff\1\3\5\uffff\1\2\1\1\4\uffff";
    static final String DFA2_specialS =
        "\16\uffff}>";
    static final String[] DFA2_transitionS = {
            "\1\2\2\uffff\1\1",
            "\1\2\5\uffff\1\3",
            "",
            "\1\7\2\uffff\1\6\1\uffff\2\5",
            "",
            "\1\11\2\uffff\1\10",
            "\1\11\2\uffff\1\10",
            "\1\11\2\uffff\1\10",
            "",
            "",
            "",
            "",
            "",
            ""
    };

    static final short[] DFA2_eot = DFA.unpackEncodedString(DFA2_eotS);
    static final short[] DFA2_eof = DFA.unpackEncodedString(DFA2_eofS);
    static final char[] DFA2_min = DFA.unpackEncodedStringToUnsignedChars(DFA2_minS);
    static final char[] DFA2_max = DFA.unpackEncodedStringToUnsignedChars(DFA2_maxS);
    static final short[] DFA2_accept = DFA.unpackEncodedString(DFA2_acceptS);
    static final short[] DFA2_special = DFA.unpackEncodedString(DFA2_specialS);
    static final short[][] DFA2_transition;

    static {
        int numStates = DFA2_transitionS.length;
        DFA2_transition = new short[numStates][];
        for (int i=0; i<numStates; i++) {
            DFA2_transition[i] = DFA.unpackEncodedString(DFA2_transitionS[i]);
        }
    }

    class DFA2 extends DFA {

        public DFA2(BaseRecognizer recognizer) {
            this.recognizer = recognizer;
            this.decisionNumber = 2;
            this.eot = DFA2_eot;
            this.eof = DFA2_eof;
            this.min = DFA2_min;
            this.max = DFA2_max;
            this.accept = DFA2_accept;
            this.special = DFA2_special;
            this.transition = DFA2_transition;
        }
        public String getDescription() {
            return "()+ loopback of 51:5: ( expression SEMICOLON | expression NEWLINE )+";
        }
    }
 

    public static final BitSet FOLLOW_statements_in_query132 = new BitSet(new long[]{0x0000000000000240L});
    public static final BitSet FOLLOW_set_in_query135 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_QUESTION_in_query137 = new BitSet(new long[]{0x0000000000000000L});
    public static final BitSet FOLLOW_EOF_in_query139 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_expression_in_statements164 = new BitSet(new long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_SEMICOLON_in_statements166 = new BitSet(new long[]{0x0000000000000202L});
    public static final BitSet FOLLOW_expression_in_statements169 = new BitSet(new long[]{0x0000000000000100L});
    public static final BitSet FOLLOW_NEWLINE_in_statements171 = new BitSet(new long[]{0x0000000000000202L});
    public static final BitSet FOLLOW_assignment_in_expression183 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_assignment192 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_ASSIGN_in_assignment194 = new BitSet(new long[]{0x0000000000001A40L});
    public static final BitSet FOLLOW_value_in_assignment196 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_constant_in_value204 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_set_in_value208 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_set_in_constant0 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_set230 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_set_constr_in_set234 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_LCURLY_in_set_constr246 = new BitSet(new long[]{0x0000000000000002L});

}